package com.du.config;

import com.du.bean.Person;
import com.du.service.BookService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;

/**
 * @author djg
 * @date 2020/11/17
 * @des 配置类==配置文件
 */


//@ComponentScan value 指定要扫描的包
//excludeFilters = Filter[] 扫描的时候按照什么规则排除哪些组件
//@ComponentScan(value = "com.du", excludeFilters = {
//        @ComponentScan.Filter(type = FilterType.ANNOTATION, classes = {Service.class})
//})

//includeFilters = Filter[] 扫描的时候只需要包含哪些组件
//useDefaultFilters 禁用掉默认的扫描规则，这样includeFilters才能生效
@ComponentScan(value = "com.du", includeFilters = {
//        @ComponentScan.Filter(type = FilterType.ANNOTATION, classes = {Controller.class}),
//        @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = {BookService.class}),
        @ComponentScan.Filter(type = FilterType.CUSTOM, classes = MyTypeFilter.class)
}, useDefaultFilters = false
)
//FilterType.ANNOTATION 按照注解
//FilterType.ASSIGNABLE_TYPE 按照给定的类型
//FilterType.ASPECTJ 使用ASPECTJ表达式
//FilterType.REGEX 使用正则表达式
//FilterType.CUSTOM 使用自定义规则
@Configuration //告诉Spring这是一个配置类
public class MainConfig {

    /**
     * 给容器中注入一个bean，类型为返回值的类型，id默认是用方法名作为id
     *
     * @return
     */
    @Bean(value = "person") //指定bean名称
    public Person person01() {
        return new Person("lisi", 20);
    }
}
